package kingwing.dc.core.view.frame.main.register.excelmodel;

import java.rmi.dgc.VMID;
import java.util.Date;
import java.util.List;

import com.bstek.bdf2.importexcel.model.ExcelModel;
import com.bstek.bdf2.importexcel.model.ExcelModelDetail;
import com.bstek.dorado.core.Configure;

/**
 * 生成Excel模板的抽象类。各个模块可以集成该类，并置于Spring容器中，将会随着服务器启动而初始化Excel模板，
 * 只会在数据库中没有任何Excel模板的时候初始化一次。
 * 
 * @author Kevin 2017年10月11日
 */
public abstract class AbstractExcleGenerator {

	/**
	 * 构造要初始化Excel模板的ExcelModel对象列表。在该方法中，
	 * 可以调用抽象父类中的createExcleModel方法生成ExcelModel对象
	 * ,调用抽象父类中的createExcleModelDetail方法生成ExcleModelDetail对象
	 * 
	 * @return
	 */
	public abstract List<ExcelModel> getExcelModels();

	protected ExcelModel createExcleModel(String excelModelId, String name,
			String excelSheetName, String tableName, String tableLabel,
			String primaryKey, String primaryKeyType, String sequenceName,
			String dbType, int startRow, int endRow, int startColumn,
			int endColumn, String processor, String helpDoc, String comment,
			String datasourceName, List<ExcelModelDetail> listExcelModelDetail) {

		String companyId = Configure.getString("bdf2.fixedCompanyId");
		ExcelModel excelModel = new ExcelModel();

		excelModel.setId(excelModelId);
		excelModel.setName(name);
		excelModel.setExcelSheetName(excelSheetName);
		excelModel.setTableName(tableName);
		excelModel.setTableLabel(tableLabel);
		excelModel.setPrimaryKey(primaryKey);
		excelModel.setPrimaryKeyType(primaryKeyType);
		excelModel.setSequenceName(sequenceName);
		excelModel.setDbType(dbType);
		excelModel.setStartRow(startRow);
		excelModel.setEndRow(endRow);
		excelModel.setStartColumn(startColumn);
		excelModel.setEndColumn(endColumn);
		excelModel.setProcessor(processor);
		excelModel.setHelpDoc(helpDoc);
		excelModel.setComment(comment);
		excelModel.setDatasourceName(datasourceName);
		excelModel.setCompanyId(companyId);
		excelModel.setCreateDate(new Date());

		excelModel.setListExcelModelDetail(listExcelModelDetail);

		return excelModel;
	}

	protected ExcelModelDetail createExcleModelDetail(String name,
			String excelModelId, int excelColumn, String tableColumn,
			String interceptor) {

		ExcelModelDetail excelModelDetail = new ExcelModelDetail();

		excelModelDetail.setId(new VMID().toString());
		excelModelDetail.setName(name);
		excelModelDetail.setExcelModelId(excelModelId);
		excelModelDetail.setExcelColumn(excelColumn);
		excelModelDetail.setTableColumn(tableColumn);
		excelModelDetail.setInterceptor(interceptor);

		return excelModelDetail;

	}

}
